﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DXApplicationTangche.UC.生产计划.编排生产批.service;
using DXApplicationTangche.UC.生产计划.生产批生产.service;
using DXApplicationTangche.UC.订单一览新.订单预览新;
using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.UC.生产计划.生产批生产.model;
using DXApplicationTangche.UC.项目成果管理;
using DXApplicationTangche.UC.项目成果管理.service;
using DXApplicationTangche.UC.订单一览新.订单预览新.service;
using DXApplicationTangche.UC.样品管理.样品订单预览;
using DXApplicationTangche.UC.全部工序.面辅料.辅料相关;
using DXApplicationTangche.DTO;

namespace DXApplicationTangche.UC.生产计划.生产批生产
{
    public partial class Form已排产 : DevExpress.XtraEditors.XtraForm
    {
        private String code { get; set; }
        private String batchNo { get; set; }
        private List<DTO生产批生产> DTO生产批s = new List<DTO生产批生产>();
        public Form已排产(String code)
        {
            InitializeComponent();
            this.code = code;
            try
            {
                //接口查询，清洗尺寸
                this.DTO生产批s = new 生产批生产Model().build清洗尺寸(生产批生产Service.get已排产一览(this.code));
            }
            catch
            {
                MessageBox.Show("无裁剪信息");
            }
            this.gridControl生产批.DataSource = this.DTO生产批s;
            this.gridView生产批.ExpandAllGroups();
            this.gridView生产批.RefreshData();
        }

        private void 查看订单ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                String orderId = FunctionHelper.GetgridViewValue(
                        this.gridView生产批,
                        this.gridView生产批.FocusedRowHandle,
                        "orderId");
                String batchNo = FunctionHelper.GetgridViewValue(
                        this.gridView生产批,
                        this.gridView生产批.FocusedRowHandle,
                        "batchNo");
                DTO生产批 dTO生产批 = 编排生产批Service.getWIPBatchByBatchNo(batchNo);
                if (String.IsNullOrEmpty(dTO生产批.orderId))
                {
                    return;
                }
                if ("48".Equals(订单预览新Service.get订单预览(orderId).shopId))
                {
                    new Form样品订单预览新(dTO生产批).ShowDialog();
                }
                else
                {
                    new Form订单预览新(dTO生产批).ShowDialog();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void 查看工序ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new Form查看工序(
                FunctionHelper.GetgridViewValue(
                    this.gridView生产批,
                    this.gridView生产批.FocusedRowHandle,
                    "batchNo"
                    )
                ).ShowDialog();
        }
        private void textBox扫码_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                if (String.IsNullOrEmpty(this.textBox扫码.Text))
                {
                    MessageBox.Show("无扫描信息");
                    return;
                }
                this.batchNo = this.textBox扫码.Text.Trim();
                try
                {
                    生产批生产Service.post扫码(
                        "yushuangqing01", 
                        this.textBox扫码.Text.Trim(),
                        this.code
                        );
                    //裁剪后状态改变重新查询
                    this.DTO生产批s = new 生产批生产Model().裁剪build清洗尺寸(生产批生产Service.get已排产一览(this.code), this.batchNo);
                    this.textBox扫码.Clear();
                }
                catch
                {
                    MessageBox.Show("无裁剪信息");
                }
                this.gridControl生产批.DataSource = this.DTO生产批s;
                this.gridView生产批.ExpandAllGroups();
                this.gridView生产批.RefreshData();
            }
        }

        private void 裁剪辅料ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new Form辅料工序(
                new WBSItemDTO("10","9","裁剪", "00.0003.0001", "ASSETES-20200929-000008"),
                FunctionHelper.GetgridViewValue(
                    this.gridView生产批,
                    this.gridView生产批.FocusedRowHandle,
                    "batchNo"
                    ),
                "yushuangqing01"
                ).ShowDialog();
        }
    }
}